package cn.itsource.hrm.service.impl;

import cn.itsource.hrm.domain.LoginUser;
import cn.itsource.hrm.domain.UserMeal;
import cn.itsource.hrm.mapper.LoginUserMapper;
import cn.itsource.hrm.mapper.UserMealMapper;
import cn.itsource.hrm.service.ILoginUserService;
import cn.itsource.hrm.util.AjaxResult;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yyx
 * @since 2021-11-02
 */
@Service
public class LoginUserServiceImpl extends ServiceImpl<LoginUserMapper, LoginUser> implements ILoginUserService {

    @Autowired
    private LoginUserMapper loginUserMapper;

    @Autowired
    private UserMealMapper userMealMapper;

    @Override
    public AjaxResult entering(LoginUser loginUser) {
        //保存到t_login_user表里
        loginUserMapper.insert(loginUser);
        //保存套餐id，
        UserMeal userMeal = new UserMeal();
        userMeal.setMealId(loginUser.getMealId());
        userMeal.setLoginId(loginUser.getId());
        userMealMapper.insert(userMeal);
        return AjaxResult.me().setSuccess(true).setResultObj(loginUser.getId());
    }

    @Override
    public AjaxResult register(LoginUser loginUser) {
        //保存到t_login_user表里
        loginUserMapper.insert(loginUser);
        //还返回了自增id>
        return AjaxResult.me().setSuccess(true).setResultObj(loginUser.getId());
    }
}
